#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <ctemplate/template.h>

#include "./oj_model.hpp"

namespace ns_view
{
    using namespace ns_model;

    const std::string template_path = "./templatehtml/";
    class view
    {
    public:
        view()
        {
        }
        ~view()
        {
        }

    public:
        void AllExpandHtml(const std::vector<question> &all, std::string *html)
        {
            /*通过表格的方式去显示，题目的编号+题目的标题+题目的难度*/
            /*使用表格去显示*/
            /*1.形成路径*/
            std::string src_html = template_path + "all_questions.html";
            /*2.形成数字典*/
            ctemplate::TemplateDictionary root("all_questions");
            for (const auto &q : all)
            {
                ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q.number);
                sub->SetValue("title", q.name);
                sub->SetValue("star", q.star);
            }
            /*3.获取被渲染的html*/
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
            /*4.开始完成渲染功能*/
            tpl->Expand(html, &root);
        }
        void OneExpandHtml(const question &one, std::string *html)
        {
            /*1.形成路径*/
            std::string src_html = template_path + "one_question.html";
            /*2.形成数字典*/
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number", one.number);
            root.SetValue("title", one.name);
            root.SetValue("star", one.star);
            root.SetValue("desc", one.desc);
            root.SetValue("pre_code",one.header);
            /*3.获取被渲染的html*/
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
            /*4.开始完成渲染功能*/
            tpl->Expand(html,&root);
        }
    };
}
